﻿using System.Collections.ObjectModel;
using Ninject.Core.Parameters;
using TestBat.IModels.Domain;
using TestBat.IModels.Models;
using TestBat.IViewModels.Base;
using TestBat.IViewModels.Workspaces.Results;
using TestBat.ServiceLocator;

namespace TestBat.ViewModels.Workspaces.Results
{
    public class ResultTraineeListViewModel : ListViewModel<IResultTraineeViewModel, ObservableCollection<IResultTraineeViewModel>>, IResultTraineeListViewModel
    {
        public ResultTraineeListViewModel(ISchedule schedule, IScheduleModel scheduleModel)
            : base(false)
        {
            this.schedule = schedule;
            this.scheduleModel = scheduleModel;
        }

        protected override ObservableCollection<IResultTraineeViewModel> _RecreateItems()
        {
            ObservableCollection<IResultTraineeViewModel> list = new ObservableCollection<IResultTraineeViewModel>();

            foreach (var test in scheduleModel.GetGradedTests(schedule))
            {
                IResultTraineeViewModel traineeViewModel = DefaultServiceLocator.Get<IResultTraineeViewModel>(With.Parameters.ConstructorArgument("test", test));
                list.Add(traineeViewModel);
            }

            return list;
        }

        private readonly ISchedule schedule;
        private readonly IScheduleModel scheduleModel;
    }
}
